import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SearchWidgetController extends GetxController {}

class SearchWidget extends StatelessWidget {
  String hintText = "输入搜索内容...";

  TextEditingController textController = TextEditingController();

  Color fillColor = Color(0xFFFEB79C);

  SearchWidget(
    this.hintText, {
    width,
    this.height = 70,
    this.onSubmitted = null,
    String value = "",
    Color this.fillColor = const Color(0xFFFEB79C),
  }) {
    if (width == null) {
      this.width = Get.width;
    } else {
      this.width = width;
    }
    this.textController.value = TextEditingValue(text: value);
  }

  double width = Get.width;

  double height = 70;

  ValueChanged<String>? onSubmitted = null;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SearchWidgetController>(
      init: SearchWidgetController(),
      builder: (controller) {
        return Container(
          width: width,
          child: SizedBox(
            child: Padding(
              padding: EdgeInsets.only(
                top: 10,
                bottom: 10,
              ),
              child: TextField(
                controller: textController,
                onSubmitted: this.onSubmitted,
                decoration: InputDecoration(
                  contentPadding: EdgeInsets.all(0),
                  prefixIcon: Icon(
                    Icons.search,
                    color: Colors.white,
                  ),
                  filled: true,
                  fillColor: fillColor,
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(20.0),
                    borderSide: BorderSide.none,
                  ),
                  hintText: hintText,
                  hintStyle: TextStyle(
                    color: Colors.white,
                  ),
                ),
                style: TextStyle(
                  color: Colors.white,
                ),
              ),
            ),
            height: height,
          ),
        );
      },
    );
  }
}
